<?php
class GridTree extends Grid
{
	public $root;
	public $openNodes;
	public $closedNodes;
	public $separator = ',';

    public function GridTree($id)
	{
        parent::__construct($id);
		$this->root = $this->GetRoot();
		$this->openNodes = $this->GetOpenNodes();
		$this->closedNodes = $this->GetClosedNodes();
		$this->viewModel->expandAll = RequestHandler::Get('expand_all');
		$this->viewModel->LoadTreeBranch($this->openNodes, $this->closedNodes, $this->root);
	}

	public function GetData()
	{
		return $this->viewModel->FindNodes($this->condition, $this->GetFieldList(), $this->orderby, $this->rpp, $this->page, $this->recordCount);
	}

    protected function GetOpenNodes()
	{
		$open = RequestHandler::Get('open');
		return explode($this->separator, $open);
	}

    protected function GetClosedNodes()
	{
        $closed = RequestHandler::Get('closed');
		return explode($this->separator, $closed);
	}

    protected function GetRoot()
	{
        $filter = RequestHandler::GetFilter();
		return isset($filter['parent_id']) ? $filter['parent_id'] : null;
	}
}
?>
